package com.hbase.api.connect;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.AsyncConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;

//多线程创建连接
public class HBaseConnect2 {

    // 设置静态属性hbase连接
    public static Connection connection = null;

    static {

        // 创建hbase的连接
        try {
            // 使用配置文件的方法
            connection = ConnectionFactory.createConnection();

        } catch (IOException e) {
            System.out.println("连接获取失败");
            e.printStackTrace();
        }
    }

    /**
     * 连接关闭方法,用于进程关闭时调用
     * @throws IOException
     */
    public static void closeConnection() throws IOException {
        if (connection != null) {
            connection.close();
        }
    }

    public static void main(String[] args) throws IOException {

       //直接使用创建好的连接
        System.out.println(HBaseConnect2.connection);

        //关闭连接
        HBaseConnect2.closeConnection();
    }
}